home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <msdos.cf>
- #include <egb.h>
- #include <tifflib.h>
- #include "graphic.h"
-
- #define TRUE 1
- #define FALSE 0
- #define ERR (-1)
-
- #define LOAD_BUF_SIZE (64*1024)
- #define DATA_BUF_SIZE (10*1024)
- #define PALT_BUF_SIZE (256*8+4)
-
- extern int screen_flg;
- extern char work[];
-
- static FILE *tiff_fp;
- static int tiff_mode;
- static int max_x,max_y;
-
- static int TIFF_read_data(char *buf, int size )
- {
- fread(buf,1,size,tiff_fp);
- return 0 ;
- }
- static int TIFF_put_data(char *buf, int lofs, int lines )
- {
- BLOCK para;
-
- para.ptn = buf;
- para.sel = getds();
- para.x1 = 0;
- para.x2 = max_x - 1;
- para.y1 = lofs;
- para.y2 = lofs + lines - 1;
- if ( tiff_mode == 1 )
- EGB_putBlockColor(work,0,(char *)¶);
- else
- EGB_putBlock(work,0,(char *)¶);
- return 0 ;
- }
- int TIFF_disp(char *file)
- {
- char *load_buf;
- char *data_buf;
- char *comp_buf;
- char *palt_buf;
- int d_line, comp, fill;
- long strip, clut, dw;
- BLOCK *save;
-
- if ( (tiff_fp = fopen(file,"rb")) == NULL )
- return ERR;
-
- if ( (load_buf = (char *)malloc(LOAD_BUF_SIZE +
- DATA_BUF_SIZE +
- PALT_BUF_SIZE +
- DECOMP_WORK_SIZE)) == NULL ) {
- fclose(tiff_fp);
- return ERR;
- }
-
- data_buf = load_buf + LOAD_BUF_SIZE;
- palt_buf = data_buf + DATA_BUF_SIZE;
- comp_buf = palt_buf + PALT_BUF_SIZE;
-
- fread(load_buf,1,LOAD_BUF_SIZE,tiff_fp);
-
- if ( TIFF_getHead(load_buf,LOAD_BUF_SIZE) < 0 ||
- (tiff_mode = TIFF_checkMode(&max_x,&max_y,&comp,
- &fill,&strip,&clut)) < 0 ||
- tiff_mode == 24 )
- goto ERROR;
-
- TIFF_setLoadFunc(TIFF_put_data,TIFF_read_data) ;
-
- /* 画面モードの設定 */
-
- MOS_disp(OFF);
- if ( screen_flg == FALSE )
- save = DSP_push_vram(0,0,639,479);
- EGB_displayPage(work,0,0);
- EGB_writePage(work,0);
- EGB_color(work,1,0);
- EGB_clearScreen(work);
- EGB_displayPage(work,0,1);
-
- switch(tiff_mode) {
- case 1: /* 2値 */
- EGB_resolution(work,0,3);
- EGB_writePage(work,0);
- EGB_color(work,0,0) ;
- EGB_color(work,1,15);
- EGB_clearScreen(work);
- break;
-
- case 4: /* 16色 */
- EGB_resolution(work,0,3);
- EGB_writePage(work,0);
- EGB_color(work,1,0);
- EGB_clearScreen(work);
- break ;
-
- case 8: /* 256色 */
- EGB_resolution(work,0,12);
- EGB_writePage(work,0);
- EGB_color(work,1,0);
- EGB_clearScreen(work);
- break ;
-
- case 16: /* 32K色 */
- if ( max_x > 320 ) { /* 高解像度モード */
- EGB_resolution(work,0,17);
- EGB_displayStart(work,3,512,480);
- } else {
- EGB_resolution(work,0,10);
- EGB_displayStart(work,2,2,2);
- EGB_displayStart(work,3,320,240);
- }
- EGB_color(work,1,0);
- EGB_clearScreen(work);
- break ;
- }
-
- dw = max_x;
- if ( tiff_mode == 4 && (dw & 7) != 0 )
- dw += 8 - (dw & 7) ;
- d_line = DATA_BUF_SIZE / ((dw * tiff_mode + 7) / 8);
-
- if ( clut != 0 ) {
- TIFF_getPal(palt_buf) ;
- EGB_palette(work,0,palt_buf) ;
- }
-
- TIFF_loadImage(tiff_mode,max_x,max_y,strip,fill,
- comp,data_buf,dw,d_line,comp_buf);
-
- mos_wait();
-
- EGB_displayPage(work,0,0);
- EGB_resolution(work,0,3);
- EGB_resolution(work,1,3);
- EGB_writePage(work,1);
- DSP_palette();
- EGB_clearScreen(work);
- EGB_writePage(work,0);
- DSP_palette();
- EGB_clearScreen(work);
-
- if ( screen_flg == FALSE )
- DSP_pop_vram(save);
-
- EGB_displayPage(work,0,3);
- MOS_disp(ON);
-
- free(load_buf);
- fclose(tiff_fp);
- return FALSE;
-
- ERROR:
- free(load_buf);
- fclose(tiff_fp);
- return ERR;
- }